/*
 * TPM_interface.h
 *
 *  Created on: Sep 17, 2013
 *      Author: uidu9161
 */

#ifndef TPM_INTERFACE_H_
#define TPM_INTERFACE_H_

#include "Common.h"
	
#define TPM__nTPM0 	TPM0_BASE_PTR
#define TPM__nTPM1 	TPM1_BASE_PTR
#define TPM__nTPM2 	TPM2_BASE_PTR

#define TPM__nError			((uint8)0x12)


#define TPM__nDiviby1		((uint8)0x00)
#define TPM__nDiviby2		((uint8)0x01)
#define TPM__nDiviby4		((uint8)0x02)
#define TPM__nDiviby8		((uint8)0x03)
#define TPM__nDiviby16		((uint8)0x04)
#define TPM__nDiviby32		((uint8)0x05)
#define TPM__nDiviby64		((uint8)0x06)
#define TPM__nDiviby128		((uint8)0x07)


#define TPM__TPM0_ISR()		

/*********************************************NEW***********************************/
#define TPM_PLLFLL      1
#define TPM_OSCERCLK    2
#define TPM_MCGIRCLK 3

#define TPM_MODULE  0x0BE8
#define DUTY_MIN  0x0000
#define DUTY_MED  0x05F4
#define DUTY_MAX  0x0BE9

#define  TPM_CNT_DIS 0
#define  TPM_CLK     1
#define  TPM_EXT_CLK 2

#define PS_1   0
#define PS_2   1
#define PS_4   2
#define PS_8   3
#define PS_16  4
#define PS_32  5
#define PS_64  6
#define PS_128 7

#define TPM_OC_TOGGLE   TPM_CnSC_MSA_MASK|TPM_CnSC_ELSA_MASK
#define TPM_OC_CLR      TPM_CnSC_MSA_MASK|TPM_CnSC_ELSB_MASK
#define TPM_OC_SET      TPM_CnSC_MSA_MASK|TPM_CnSC_ELSA_MASK|TPM_CnSC_ELSB_MASK
#define TPM_OC_OUTL     TPM_CnSC_MSB_MASK|TPM_CnSC_MSA_MASK|TPM_CnSC_ELSB_MASK
#define TPM_OC_OUTH     TPM_CnSC_MSB_MASK|TPM_CnSC_MSA_MASK|TPM_CnSC_ELSA_MASK

#define TPM_PWM_H       TPM_CnSC_MSB_MASK|TPM_CnSC_ELSB_MASK
#define TPM_PWM_L       TPM_CnSC_MSB_MASK|TPM_CnSC_ELSA_MASK

#define EDGE_PWM     0
#define CENTER_PWM      1

/***************************************END NEW*************************************/
typedef enum{
	TPM_enNoError = 0,
	TPM_enNoValidParam,
	/*Max number*/
	TPM_enMaxErrorNum	
}TPM_tdErrorNum;

typedef enum{
	TPM_enDisable = 0,
	TPM_enMCGFLLCLK,
	TPM_enOSCERCLK,
	TPM_enMCGIRCLK,
	/*Max number*/
	TPM_enMaxCLKnum
}TPM_tdCLKsrc;
		
TPM_tdErrorNum TPM_Init (TPM_MemMapPtr TPMmodule,TPM_tdCLKsrc tdCKLsrc ,uint32 u32clk_khz, uint32 u32Tick_khz);

void TPM_init_PWM(TPM_MemMapPtr TPMx, int  clock_source, int module, int clock_mode, int ps, int counting_mode);

void TPM_CH_init(TPM_MemMapPtr TPMx, int channel, int mode);

void set_TPM_CnV(TPM_MemMapPtr TPMx, int channel, int value);

#endif /* TPM_INTERFACE_H_ */
